player = null;
currentVolume = 100;

function createPlayer(url) {Common.log('creamos el player con la url:<br/>'+url);
    var flashvars = {
            file: url,
            autostart:"true"
    }
    var params = {
            allowscriptaccess:"always",
            bgcolor:"#2A2A2A"
    }
    var attributes = {
            id:"reproductor",
            name:"reproductor"
    }
    swfobject.embedSWF("../../common/jwplayer/player.swf", "reproductor", "233", "19", "9.0.115", false, flashvars, params, attributes);
}
 
function playerReady(thePlayer) { 
    player = document.getElementById(thePlayer.id);

    player.sendEvent('VOLUME', currentVolume)

    addListeners();
}

function addListeners() {
    if (player) {
        player.addModelListener("STATE", "stateListener");
        player.addControllerListener("VOLUME", "volumeListener");
    } else setTimeout("addListeners()",100);
}

function volumeListener(obj) {
    currentVolume = obj.percentage;
}

function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
    currentState = obj.newstate;
    previousState = obj.oldstate;
    if ((currentState == "COMPLETED")&&(previousState == "PLAYING")) {
        //set_cookie( 'volume', currentVolume, cookie_year, cookie_month, cookie_day );
        var id_cancion_siguiente = Canciones.get_id_cancion_siguiente()
        Canciones.reproducir_cancion(id_cancion_siguiente);
    }
}